﻿using System.Data.Entity;

namespace Quadrant.domain.DB
{
    public class QuadrantContext : DbContext
    {
        public QuadrantContext()
            : base("QuadrantConnection")
        {
            //Configuration.ProxyCreationEnabled = true;
            //Configuration.LazyLoadingEnabled = true;
        }

        public QuadrantContext(string connection)
            : base(connection)
        {
        }
        public DbSet<Models.QuadrantUser> QuadrantUsers { get; set; }
        public DbSet<Models.Quadrant> Quadrants { get; set; }
        public DbSet<Models.Zone> Zones { get; set; }
        public DbSet<Models.Stick> Sticks { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Models.Stick>().HasRequired<Models.Quadrant>(s => s.Quadrant).WithMany(p=>p.Sticks).WillCascadeOnDelete(true);
            modelBuilder.Entity<Models.Zone>().HasRequired<Models.Quadrant>(s => s.Quadrant).WithMany(p => p.Zones).WillCascadeOnDelete(true);
            modelBuilder.Entity<Models.QuadrantUser>().HasMany<Models.Quadrant>(s => s.Quadrants).WithRequired(p => p.Owner).WillCascadeOnDelete(true);    
        }
    }
}
